﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting;

namespace Seed.IoC
{
    public class MefServiceLocator : IServiceLocator
    {
        public T Resolve<T>()
        {
            return _container.GetExportedValue<T>();
        }

        public IEnumerable<T> ResolveAll<T>()
        {
            return _container.GetExportedValues<T>();
        }

        public MefServiceLocator(CompositionContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            _container = container;
        }

        private readonly CompositionContainer _container;
    }
}